<?php
class Admini_RemotefeeController extends Uuch_ManageController {
    
    public function init() {
        parent::init();
        $this->appendCss('/admins/css/yundan.css');
        $this->appendCss('/admins/css/common.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
        $this->setTitle("偏远费管理");
        $this->view->type = "Relevance";
    }    
       
    public function indexAction()
    {
        $pagesize = 60;
        $pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
        $stateId = $this->getSafeParam("stateId");
        $startZip = $this->getSafeParam("startZip");
        $endZip = $this->getSafeParam("endZip");
        $remoteItem = Application_Model_RemoteFee::getRemoteFeeFileds($stateId,$startZip,$endZip,$pagesize,$pageindex);
        $this->view->remoteAll = $remoteItem;
        $this->view->remoteList = $remoteItem["list"];
        
        $stateId = $stateId?$stateId:1;
        $this->view->stateId = $stateId?$stateId:1;
        $this->view->stateName = Application_Model_city::load($stateId)->Name;
        $this->view->startZip = $startZip;
        $this->view->endZip = $endZip;
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        $this->view->type = "Relevance";
        $this->view->stype = 1;
    }
    
    public function addoreditremotefeeAction()
    {
        $editId = $this->getSafeParam("editId");
        $stateId = $this->getSafeParam("addstateId");
        $startZip = $this->getSafeParam("addStartZip");
        $endZip = $this->getSafeParam("addEndZip");
        $remoteFeeId = Application_Model_RemoteFee::addOrEditRemoteFee($editId,$stateId,$startZip,$endZip);
        if($remoteFeeId != ""){
            $this->json(1);
        } else {
            $this->json(0);
        }
    }
    
    public function delremotefeeAction()
    {
        $id = $this->getSafeParam("delId");
        $remoteFeeItem = Application_Model_RemoteFee::load($id);
        if($remoteFeeItem){
            Application_Model_Operate::addOperate(0, null, $remoteFeeItem->Id, "删除偏远费".$remoteFeeItem->StateName."(".$remoteFeeItem->StartZip."~".$remoteFeeItem->EndZip.")", 0);
            $remoteFeeItem->delete();
            $this->json(1);
        } else {
            $this->json(0);
        }
    }
    
    public function remotefeeinfoAction()
    {
        $editId = $this->getSafeParam("editId");
        $remoteFeeItem = Application_Model_RemoteFee::load($editId);
        if($remoteFeeItem){
            $this->json(array("type"=>1,"stateId"=>$remoteFeeItem->StateId,"stateName"=>$remoteFeeItem->StateName,"startZip"=>$remoteFeeItem->StartZip,"endZip"=>$remoteFeeItem->EndZip));
        } else {
            $this->json(array("type"=>0));
        }
    }
   
}
